<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>材质</title>
    <script src="http://www.yanhuangxueyuan.com/versions/threejsR92/build/three.js"></script>
    <link rel="stylesheet" href="common.css">
</head>

<body>

</body>
<script>
    // 【第一步：创建模型、材质】,材质共有属性（side，opacity）
    // 1.【创建点材质对象point】
    var scene = new THREE.Scene(); //  创建场景对象Scene
    var geometry1 = new THREE.SphereGeometry(60, 25, 25); //创建一个球体几何对象
    var material1 = new THREE.PointsMaterial({
        color: 0x00ffff,
        size: 1,
    });
    var point = new THREE.Points(geometry1, material1); //网格模型对象Mesh（模型，材质）
    scene.add(point); //将模型添加到场景中
    geometry1.translate(200, 0, 0); // 几何体沿着x轴平移50

    // 2.【创建线材质对象line】
    var geometry2 = new THREE.SphereGeometry(60, 25, 25)
    var material2 = new THREE.LineBasicMaterial({
        color: 0x0000ff
    })
    var line = new THREE.Line(geometry2, material2)
    scene.add(line);
    geometry2.translate(0, 200, 0)

    // 3.【创建网格模型mesh】：
    // MeshBasicMaterial(不受带有方向光源影响，没有棱角感)
    var geometry3_1 = new THREE.SphereGeometry(40, 25, 25)
    var material3_1 = new THREE.MeshBasicMaterial({
        color: 0x00ff00
    })
    geometry3_1.translate(0, 0, 100)
    var mesh_1 = new THREE.Mesh(geometry3_1, material3_1);

    //  MeshLambertMaterial(表面与光源的漫反射光照计算，棱角感)
    var geometry3_2 = new THREE.SphereGeometry(40, 25, 25)
    var material3_2 = new THREE.MeshLambertMaterial({
        color: 0xffff00,
        transparent: true, // transparent设置为true，开启透明，否则opacity不起作用
        opacity: 0.3,
        side: THREE.DoubleSide,
    })
    geometry3_2.translate(0, 0, 200)
    var mesh_2 = new THREE.Mesh(geometry3_2, material3_2);

    // MeshPhongMaterial(表面与光源的漫反射光照计算，棱角感，高光效果)
    var geometry3_3 = new THREE.SphereGeometry(40, 25, 25)
    var material3_3 = new THREE.MeshPhongMaterial({
        color: 0xff00ff, //材质颜色
        specular: 0xffffff, //高光颜色
        shininess: 10, //高光亮度，默认30
    })
    geometry3_3.translate(0, 0, 300)
    var mesh_3 = new THREE.Mesh(geometry3_3, material3_3);
    scene.add(mesh_1, mesh_2, mesh_3);


    // 【第2步：光源设置】
    var point = new THREE.PointLight(0xffffff); //设置点光源
    point.position.set(400, 200, 300); //点光源位置
    scene.add(point); //点光源添加到场景中

    // 【第三步：相机设置】
    var width = window.innerWidth; //窗口宽度
    var height = window.innerHeight; //窗口高度
    var k = width / height; //窗口宽高比
    var s = 400; //三维场景显示范围控制系数，系数越大，显示的范围越大
    var camera = new THREE.OrthographicCamera(-s * k, s * k, s, -s, 1, 1000); //创建相机对象
    camera.position.set(200, 300, 200); //设置相机位置
    camera.lookAt(scene.position); //设置相机方向(指向的场景对象)
    var axisHelper = new THREE.AxisHelper(600); // 辅助坐标系
    scene.add(axisHelper); //场景中加入辅助线

    // 【第四步：渲染对象】
    var renderer = new THREE.WebGLRenderer();
    renderer.setSize(width, height); //设置渲染区域尺寸
    renderer.setClearColor(0xb9d3ff, 0.3); //设置背景颜色
    document.body.appendChild(renderer.domElement); //body元素中插入canvas对象
    renderer.render(scene, camera); //执行渲染操作（场景、相机）
</script>

</html>